home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!news
- From: Bradd W. Szonye <bradds@ix.netcom.com>
- Newsgroups: comp.lang.c++
- Subject: RE: cout and colors; help
- Date: 19 Apr 1996 09:56:20 GMT
- Organization: Netcom
- Message-ID: <01bb2dd6.c0293d40$c6c2b7c7@Zany.localhost>
- References: <4k9ut6$q8_001@basmith1.iquest.net>
- NNTP-Posting-Host: det-mi6-06.ix.netcom.com
- X-NETCOM-Date: Fri Apr 19 4:56:20 AM CDT 1996
- X-Newsreader: Microsoft Internet News
-
-
- On Sunday, April 07, 1996, Brian Smith wrote...
- > I'm new to C++, using Borland Turbo C++ for DOS version 3.0.
- >
- > I wrote a small program that used different text colors, and all my
- screen
- > output was with putch() or cprintf(). When I tried to use cout, I lost
- the
- > ability to set the colors with textcolor(). Surely there's a way to use
- cout,
- > with it's much simpler syntax, and still have control over colors, but I
- can't
- > find it, either in the manual or the on-line help.
- >
- > Any assistance w/b greatly appreciated.
- >
- > Brian Smith
- >
- >
- Okay, I'm a little rusty with this, but I might be able to help.
- You want to define a custom manipulator. (Like cout << width(5) << x <<
- endl;).
-
- They're easy to write if you don't want it to take a parameter:
-
- ostream& blue(ostream& s)
- {
- s.flush(); // make sure text so far is written
- textcolor(BLUE); // usual command to change color
- }
-
- You can do the same for red, green, etc.
-
- To write "cout << color(BLUE) << x << endl;" is a little trickier, but it
- can be done. I don't remember how off the top of my head, but you can find
- the technique in tutorials that describe either "iostream manipulators" or
- the header "iomanip.h"
-
-
-